Okay, so in today's lecture we are going to start finishing off our job.
Really?
Um, we already have all of our stages and our final section that we've been doing over the last couple
lectures, and we're writing the more major scripts here.
Really.
Um, this will be the second to last lecture.
So in today we're going to be, um, doing the saving script between checkpoints.
So obviously when you go to the first checkpoint, you'll then in stage two, which then means if you
die while you're doing stage two, you respawn here and not right at the start, for example, it's
a very important one to make.
We will then also have a look at a label and a timer up here, showing you how long your account is
taking on that stage and what stage you're on as well.
That will most likely be started today, but finished off in the next lecture, and also some minor
tweaks and changes and additions that we want to make before we finish this off.
That will all probably come next lecture as well.
Okay, so um, first thing we're going to do is make this, um, saving system.
Now there are a couple ways to do that, but we're going to stick to easiest ways and that's to use
teams.
So teams the whole section in explorer down here in teams.
And you can create teams and assign a player to each team.
Um, as I've already looked at earlier on in the course.
So I'm going to add in six teams, one for each stage and one for like the finish.
Once you get to the end as well.
Okay.
So let's add in a team.
And change this to be stage space one.
Now I know I always say to not include spaces and have included a space was done.
The reason I have is because the name is exactly how it will display on the leaderboard.
Okay, so you do.
You don't want to be including a space this time.
Okay.
Let's duplicate this 123, four five, five times and change these around space to be stage two.
Um.
Stage three.
Stage.
Or.
Stage five.
And then I'm just going to call this finish.
Finish.
Okay.
So immediately if I go in and just play the game.
Um, you'd be able to see it displays some stuff here just to.
It just shows finished at the moment.
Um, because only shows it will only show a team once a player has been assigned to it.
Um, but you'll be able to see them a bit later on once we start coding it.
Um, so that's for team sorted.
We now need to match the teams against the spawn locations.
So we have all our spawn locations around here, but we basically need to assign each spawn location
to be per team basically.
So like this.
If a spawn location of a team for the team.
Stage one.
This was born.
Location of the team.
Stage two um, and we do that by giving them the same team color.
So each team has its own team color.
So we need to first decide what color we're going to give other teams and match them up to the colors
at spawn locations, basically.
Um, also make sure just remind me to myself here or to assignable needs to be off for all of them apart
from stage 1 or 2.
Assignable means when you join the game, are you automatically given that team?
Now you do automatically want to start a stage one, so that will be ticked for stage one, but off
all the other ones.
Because you do not want to start, you don't want the player to start anywhere else apart from a stage
one.
Let's go through and give all these unique team colors.
So I'm going to do it matching to kind of what the level looks like.
So this is a very gray kind of level.
So um let's give it dark stone gray.
Um stage two has got the lava parts.
So obviously we're going to make this, um, a nice red.
Stage three is kind of like grass.
Um, so let's give that, like, a dark green.
Stage four has these blue bits here, so maybe I'll give it a blue.
You can change these to whatever ones you'd like.
In this one we've already used blues.
I guess I'll use yellow.
And then the finish.
Oh, can't use green.
Um, quite yellow, but I've already got yellow.
I'll go white for the house.
Leave it as it already is.
Okay.
So let's then go through all of these spawn locations.
So nice and simple to search them up and match them over to the teams.
Now need to remember which one assigned each one, which might be a little bit tricky.
Um.
Yeah.
No.
Can't remember.
Okay.
Um, stage one is let's just do it one by one.
So stage one is dark stone gray.
So stage one, stage parts.
Without spawn location for stage one.
Oh.
It's here.
Okay.
Um, this will be, um, dark stone grey.
Cool.
Stage two is really red.
So, um, of course we have them in, um, because it's a, it's a spawned and then the other ones have
it there.
So, um, go inside here.
Spawn location.
And change this to really red.
We also need to make sure neutral is ticked off as well.
We'll go through and change that all themselves as well.
Neutral basically means does this spawn location and match a certain team?
You want that off.
So it does match a certain team.
If it's neutral, it doesn't match.
It's kind of it's spawn occasion not all teams can use rather than a specific team.
Stage three is dark green.
So stage three dark green.
Dark green drones.
Dark green.
That ones dark green.
Cool.
Stage four is electric blue.
So let's go over to here.
Set this to be electric blue.
Cyan as electric blue.
Cool.
Um, stage five is new yellow.
So stage five spawn location.
New yellow.
That's medium green.
You want new yellow?
Cool.
And then finally the finish is white.
So over in the finish spawn location.
Because it would not be good if you.
Oh, that's.
Lily white.
Which one's white, then?
Quite a few white colors.
White.
There we go.
Okay, cool.
Um, yeah, because it would not be good if you were had finished the game.
Cool.
You accidentally fallen off because you're going really fast with these walk speed parts, and then
you just start right at the start of the of the obby.
You don't want that.
Um, cool.
So that's all of the stuff behind the scenes.
Um, coded, not coded.
So that's all the stuff behind the scenes set up.
We now need to code it.
So I'm going to add a script into server script service.
Um, a standard script and all.
We need to make this a lot bigger.
Cool, a bit difficult for you to see otherwise.
And we're just going to call this team spawning.
Doesn't matter too much.
Okay, cool.
So, um, this will be quite a simple script.
How this is going to work is we are going to give them the, um, team the spawn location has.
So here, for example, we're going to give them, um, the stage two team once they have touched this
spawn location.
That's quite typical for most when you touch the spawn location and make sense, um, you then will
be spawn there if you die.
So we first need to go through and um, make a variable for all of these different spawn locations.
So a bit tedious, but um.
Yeah.
So, spawn.
One is equal to.
Um, no, actually we don't need spawn one because it's automatically assigned.
So we're only looking at spawn two and onwards.
Spawn two is equal to game dot workspace dot stage two dot spawn location I'm going to copy this.
Copy this line 345 and the finish and just go through and change all these.
For.
Five.
I'm going to call it spawn finish.
Just finish spawn.
Okay.
And then change them all here as well.
Now, I know it might seem a bit weird, but we are making all these variables for quite small things.
But, um, variables save you time.
And also remember, it will just make our code kind of flow a bit more later on as well.
So I'd always recommend doing so, even if maybe it might not be faster.
It's going to make it a lot easier to read.
Okay.
So we're going to make a simple game players dot player added.
And this will occur when the player joins the game.
The reason why we want to do this is we then have a nice, easy reference of the player, which we're
going to need the player in order to change their team, to change their team.
There's a property inside the actual player.
So if I click on myself here, um, scroll down team.
Here you can assign the player's team through here.
So that's what we're going to be doing.
Um, basically just that really.
So let's um, start off with spawn two.
So spawn two making a dot touched event and connect that with our new function.
And we will need a hit parameter in there as well.
Cool.
So obviously we need to check to make sure that, um, whatever's colliding with is a is a player and
not anything else.
So if hit dot parent not wait for child find first child humanoid.
If it finds a humanoid and they really want to change a player's team.
And this is quite easy.
We just need to write down player dot team that references this property here.
And we're going to make that equal to, um, the stage in the teams.
Now of course this is where it gets a little bit tricky because they have a space in their name.
We have to reference it in the different way.
I explained this right at the start when referencing.
I probably haven't done it too much since.
Um, so let's see.
We'll take a minute to remember and I'm going to write it out.
So it's game dot teams then these I call them square brackets.
It's probably not their technical name with speech marks.
Stage two okay.
So it's done using the um square brackets and then the speech marks just like that.
Cool.
And we're just going to repeat that code really for the rest of them.
So it's quite a repetitive script.
Um, I mean we could use like we could use tables and stuff to shorten it down, but I think sometimes
you've kind of got to think, is it worth worth it?
Almost.
Because if we're only repeating it a couple of times, it's not always worth making it a bit more complex.
And it has to be, especially with tables and using for comma V, there's always extra things you have
to do and set up and stuff, so sometimes absolutely worth it.
But other times it might just be simpler not to.
Um.
Cool.
I definitely would have consider it if the code for each one would be larger.
Especially it's just like four lines, each one.
Um, finish.
Cool.
And that's it.
Pretty much.
So a pretty basic script.
Um, doing our doing our variables.
When the player is added, when it touches any spawns, give it that team there basically.
So let's go ahead play the game and give this a try out.
So you can see all these teams here now.
Um, so we're assigned team one automatically, which is perfect.
Let's go through and start, um, seeing if all this works.
Let's just do our jumps here.
Go up cool and nice.
I have now been automatically assigned to stage two.
That's perfect.
Okay, and just to make sure it works, you can do stage three as well.
If I can manage it now, I can't manage it.
Okay.
Um, let's try again.
Be careful here.
I have to jump and then move, not move and jump.
My legs will touch it.
Cool.
And I've now been assigned there.
Level three.
Perfect.
So a nice easy script, but it's very effective when it comes to saving.
Um, now, this will not work if the player leaves and then joins again.
They will start at right at the scratch.
Write a scratch there.
That is using data stores, which is something we haven't even covered yet, so won't be able to show
you, but is something you will learn on later on in the course.
And it wouldn't necessarily be needed unless your OB is like hundreds of pages long in which you might
want to consider that.
Um, cool.
Perfect.
So we have that script, um, all nice and working there.
Um, I'm going to start up.
We'll start looking at now is the, um, timer and the label to show what stage you're on, basically.
Um, so this was something we probably start in this lecture and then finish off in the next lecture.
Okay.
So we're going to need to go into, um, start and make our make a GUI here.
So let's add in a screen GUI.
Let's just call this.
Staged UI.
Cool.
And.
Ignore null set will be on ignore null set means it's displayed right at the top.
We're going to want.
We're going to want that.
And everything else would be fine.
And we're going to add in a to text labels.
One is going to display the stage you're on.
And the other one, the actual timer that we're going to have a look at making.
So let's call this.
Stage label.
Text.
It's just called stage one.
And let's just get this looking a bit nicer than it is at the moment.
So I'm going to use, um, anchor point at 0.5 to anchor it in the center like that there.
I'm going to scale the text up nicely.
I want to copy this font that I used here.
Um, this is nice to keep things consistent.
Your game looks much, much nicer when everything is consistent.
Um, it's not actually why it's in text label.
Here we are using Frodo one.
So I'm going to I'm going to copy that as well.
Um.
Frodo one.
Cool.
And that's the same color and stuff as well.
Um, get rid of the background.
You don't want that.
And what a nice little, um, guy there showing what stage we're on.
Cool.
Let's copy that and make a slightly smaller one underneath.
Oh no.
Sorry.
The size is using offset.
And then back to remember back to everything the guys lesson on using scale on offset.
We definitely want to be using scale.
So 0.2 looks nice and maybe 0.15.
Point one.
That looks nice.
Cool.
Let's duplicate this and rename this to be Timer Label.
Cool and let's move it down.
Um.
To worst way too low 0.1.
I want to make it.
I want to make it slightly smaller as well.
I think that'll look nice.
Kind of like that.
And this will just have like a basic.
Nice, cool.
So you can play around with that a bit more if you like.
Again, you don't have to copy my style or copy anything I'm doing here.
Really.
Um, but that's I think the set I'm set up, I'm going to like there.
Um, cool.
So, um, let's add a local script inside of here and start coding the timer and the label display and
all of that kind of stuff.
So this is going to be a bit of a larger script.
We're going to start off today and then we're going to continue it in the next lecture.
Um.
So the first we'll come, we'll come on to that.
Okay.
So let's first make our make some variables to start off with.
So be nice and easy.
If we can reference the stage guy as the script's parent the stage label.
Which is stage by stage label and then local timer label is equal to stage.
Part time.
Now there's two kinds of scripters.
There's the ones who make all their.
Make all their variables first, and then kind of go for it.
Or the ones that start with no variables.
Start coding and kind of realize, oh, make a variable for that.
I'm kind of a mix, but, um, I do like to think ahead and think, what things am I going to definitely
need and add some more as we go along, basically.
Okay.
Um, cool.
Now, um.
This time now.
Last time didn't use tables and stuff.
I'm going to do this time because the code will be a little bit longer to do and also want to show you
both methods.
So we're going to make a table full of all of the stages.
So this will be not string stage one.
That's not too useful.
This will actually be referencing all the folders and stuff.
So game dot workspace dot stage one.
Game dot workspace dot stage two.
Oh game that workspace.
Stage three.
Game that works based stage four.
Forget the comma game, the workspace stage five and we don't need to finish there.
This will come in useful so we know when to like cycle through all this stuff basically.
Okay.
Oh, we're also going to need the player as well.
Can't do much if we don't have the player now, can we?
Player is equal to game dot players dot local player.
Okay.
So, um.
What can we do?
Um.
Okay, let's do another part.
We're going to do this lesson.
Okay.
So, um, we are now going to run some code which will repeat for all those stages.
Now we're going to focus on getting the actual stage itself to work first and then next lesson, next
lecture.
We can have a look at the timer there.
So this will be using a four icon.
I'm going to say for I in stage in pairs just to make it a bit clearer.
In stages, so this code will run for each of the stages we have in there.
Cool.
So each stage you remember, we had a start and an end part.
Um, each one has a start and an end part.
And this shows where it's going to start and where it's going to end, basically.
And they're very important for us.
Um, this is where that's going going to, going to come kind of going to kind of come in handy.
Um, so we have the start part, which will, um, let us know that we've started.
They've started, um, this stage, which is, which is more useful for the actual timer, to be honest.
And in the end, you know, that you've then gone on to the next level.
So then change the timer label.
So we're going to write write the code for this and then probably finish it here for today's lecture.
So stage.
So just stage.
Stage.
Dot start.
Dot touch.
Again, we're using another touch event.
They are the most common type of type of event and function hit.
You'll be fine.
You use using a lot if hit dot parent.
Um.
Find first child.
Humanoid.
Then, um, when we're going to just assign the stage labels text to equal.
Um, now we can't specifically say equal stage one or equal stage two because remember this is being
repeated for all of these here.
So we kind of need to do it in a way which allows it to be repeated no matter what stage it is.
And um.
Don't be a bit tricky.
We can't.
So we could say, okay, just do, um, stagename, for example.
But that would give us this without a space in it.
Which I don't want.
Okay.
Let's, um.
Yeah, I know what to do.
We can add a, um, stage name string value into the, um, into the start parts.
So, um, start.
Add string value.
Oh.
Let's call this.
Stage name, and this will include it with a space.
So this is stage five.
So stage space five.
You do have to do this kind of weird workarounds when it comes to tables and stuff, but it's worth
doing.
So let me copy that.
And for the rest of the start parts minus stage five.
I'm going to just paste them in there.
Cool.
So, um, that's stage five.
Done.
Let's just search up stage name.
So the start.
And that's stage five.
This one should be stage four.
This one will be stage one.
This wannabe.
Stage three.
And this one to be staged too.
Perfect.
So through here we can then say, um, stage will be equal to stage dot start dot stage name.
Dot value.
Cool.
Let's just test that out quickly and we will leave it there for.
Oh actually got rid of the explorer.
We do want that.
Okay.
Let's give that a go.
So we'll repeat that for all the stages.
So whenever you touch the start part, it'll tell you what stage we're on.
And why am I in stage four?
Start as a member of Workspace Stage one.
So, um.
Stage one.
Okay, so my ways, my way.
Um, the thing that I always would assume with these kind of things is that it's telling me start is
not band member, so it doesn't exist, but it does exist.
I always like to put a quick weight at the top of my script, maybe for, um, about two seconds, and
put that actually before your reference for stages just gives time for things to load and things like
that.
Um, that's always something that usually fixes our issue.
Oh, look at that.
We, um.
We're stage.
Stage two.
Even though.
He shouldn't be.
Mm made.
Let's make sure the teams are all to a assignable off.
Um.
What?
Assignable.
Stage one.
What happens if I do it again?
Is it just a one time thing or is it like every time?
Yeah, okay.
My guess is maybe it's the wrong color.
Dark stone grey.
Neutral is on.
That's why.
Turn that off.
I know, I said to my I said I said earlier, let's go through and change the more neutral to be off,
I never did.
Uh, neutral off.
Okay, now I'm confident this will work.
Stage one.
Okay, cool.
Let's go over to stage two to make sure this all works nicely.
Um.
Over and we're now at stage two.
That's perfect.
Cool.
So, um, we'll leave it there for today's lecture.
Um, just have to split this script into into half, unfortunately.
But, um, the next lecture, we will be finishing off that script, making couple other final changes,
and we'll be done, um, with RB, which is quite exciting.
So, um, I will see you my next lecture.